using System;
using BitMango;
using Data;

public static class SyncPackage
{
	public static void Sync()
	{
		foreach (Package package in DataContainer<Data.Root>.Data.packages)
		{
			if (Wallet.GetItemCount("unlockall") > 0 && package.record.isLocked)
			{
				package.record.isLocked = false;
				package.SaveContext();
			}
			if (string.IsNullOrEmpty(package.iap) && package.record.isLocked)
			{
				package.record.isLocked = false;
				package.SaveContext();
			}
			if (package.record.isClear && !package.levels[package.levels.Length - 1].record.isClear)
			{
				package.record.isClear = false;
				package.SaveContext();
			}
			else if (!package.record.isClear && package.levels[package.levels.Length - 1].record.isClear)
			{
				package.record.isClear = true;
				package.SaveContext();
			}
		}
		for (int j = 1; j < DataContainer<Data.Root>.Data.packages.Length; j++)
		{
			if (!DataContainer<Data.Root>.Data.packages[j].isPremium && DataContainer<Data.Root>.Data.packages[j].mode.Equals(DataContainer<Data.Root>.Data.packages[j - 1].mode) && DataContainer<Data.Root>.Data.packages[j].record.isLocked && DataContainer<Data.Root>.Data.packages[j - 1].record.isClear)
			{
				DataContainer<Data.Root>.Data.packages[j].record.isLocked = false;
				DataContainer<Data.Root>.Data.packages[j].SaveContext();
			}
		}
	}
}
